#!/bin/bash
# 生成 FaceApi javascript(jquery) client代码脚本
sh_folder=$(cd "$(dirname $0)"; pwd -P)
pushd "$sh_folder"
OUT_FOLDER=$sh_folder/../faceapi-client-ext/jquery

# 指定thrift compiler位置
[ $(which thrift) >/dev/null ] && THRIFT_EXE=thrift
[ -z "$THRIFT_EXE" ] && THRIFT_EXE=$sh_folder/dependencies/dist/thrift-$(g++ -dumpmachine)/bin/thrift
[ ! $("$THRIFT_EXE" --version) ] && echo "not found thrift,please build thrift" && exit 255

if [ -e "$OUT_FOLDER" ] ;
then
	rm "$OUT_FOLDER/FaceApi*" >/dev/null 2>/dev/null
	rm "$OUT_FOLDER/FeatureSe*" >/dev/null 2>/dev/null
else
	mkdir -p "$OUT_FOLDER"
fi

$THRIFT_EXE --gen js:jquery \
	-out "$OUT_FOLDER" \
	$sh_folder/../faceapi-service/FaceApi.thrift || exit

$THRIFT_EXE --gen js:jquery \
	-out "$OUT_FOLDER" \
	$sh_folder/../faceapi-service/FeatureSe.thrift || exit

# 复制生成的js代码到demo项目
cp -vf "$OUT_FOLDER"/* src/main/resources/META-INF/resources/demo/client/js/ || exit
popd
